package com.rick.new1125;

import java.util.function.Predicate;

/**
 * @author xjli2
 * @Classname Function2If
 * @Description TODO
 * @Date 2021/12/10 15:44
 */
public class Function2If {


    public static void main(String[] args) {
        isPass(-1, o -> {
            return Integer.parseInt(String.valueOf(o)) > 0;
        }).throwMessage("参数不能大于0");

        isPass(2, o -> (int) o > 0).throwMessage("\"参数不能大于0\"");
    }

    static <T> ThrowExceptionFunction isPass(T t, Predicate predicate) {
        return msg -> {
            if (predicate.test(t)) throw new RuntimeException(msg);
        };
    }
}
